package com.briup.day21;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test_Thread {
    public static void main(String[] args) {
        //获取线程池【2个线程】
        ExecutorService pool = Executors.newFixedThreadPool(2);
        MyRunnable r = new MyRunnable();
        pool.submit(r);
        pool.submit(r);
        pool.submit(r);
        //释放线程
        pool.shutdown();
    }
}
class MyRunnable implements Runnable {
    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        System.out.println("我需要一个教练（共享资源）");
        System.out.println("教练来了"+name);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("教完了，放回池子");
    }
}
